home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Updates / HD-Installer / -WHDLoad- / WHDLoad_dev / Src / sources / savegame.s < prev    next >
Text File  |  1999-11-08  |  15KB  |  746 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    savegame.s
  3. ;  :Contents.    routine for multiple save game support
  4. ;        it creates an interface from which the user can choice between
  5. ;        9 different savegames, a description can be entered for each
  6. ;        savegame, all savegames will be stored in one single file which
  7. ;        grows dynamically
  8. ;        the savegames must have always the same size
  9. ;  :Author.    Wepl
  10. ;  :Version.    $Id: savegame.s 1.1 1998/06/27 23:53:54 jah Exp jah $
  11. ;  :History.    14.06.98 extracted from Interphase slave
  12. ;        15.06.98 returncode fixed
  13. ;             problem with savegames larger than $7fff fixed
  14. ;  :Requires.    _keyexit    byte variable containing rawkey code
  15. ;        _exit        function to quit
  16. ;  :Copyright.    Public Domain
  17. ;  :Language.    68000 Assembler
  18. ;  :Translator.    Barfly V2.9
  19. ;  :To Do.
  20. ;---------------------------------------------------------------------------*
  21. ; this is a example sequence to use the savegame routine
  22. ; during execution some custom registers will be destroyed, if the installed
  23. ; program does not refresh them itself, it must be done after calling the
  24. ; savegame routine
  25.  
  26.     IFEQ 1
  27.  
  28.         move.l    #100,d0            ;savegame size
  29.         lea    $3e900,a0        ;address of savegame
  30.         lea    $65000,a1        ;free mem for screen
  31.         bsr    _sg_load
  32.     ;    move.w    #$4100,(_custom+bplcon0)
  33.     ;    move.w    #320/8*3,(_custom+bpl1mod)
  34.     ;    move.l    #$00000eee,(_custom+color)
  35.  
  36.     ENDC
  37.  
  38. ;--------------------------------
  39. ; IN:    d0 = ULONG size (only on function save required)
  40. ;    a0 = APTR  address of load/save area
  41. ;    a1 = APTR  space for the screen ($2800 bytes)
  42. ; OUT:    d0 = BOOL  success
  43. ;    d1/a0/a1 destroyed
  44.  
  45. MAXNAMELEN    = 40
  46. LINE        = 320/8
  47. SCREEN        = LINE*200
  48. SAVEDIRLEN    = 4+10+(10*MAXNAMELEN)
  49. CHARHEIGHT    = 5
  50. CHARWIDTH    = 5
  51.  
  52.     INCLUDE    macros/ntypes.i
  53.  
  54.     NSTRUCTURE    SaveGame,0
  55.         NLONG    sg_screen
  56.         NLONG    sg_size
  57.         NLONG    sg_address
  58.         NLONG    sg_old68
  59.         NLONG    sg_old6c
  60.         NWORD    sg_oldintena
  61.         NWORD    sg_olddmacon
  62.         NSTRUCT    sg_save_names,10*MAXNAMELEN
  63.         NSTRUCT    sg_save_flags,10
  64.         NSTRUCT    sg_save_id,4
  65.         NSTRUCT    sg_tmpname,MAXNAMELEN
  66.         NWORD    sg_c_x
  67.         NWORD    sg_c_y
  68.         NBYTE    sg_key
  69.         NBYTE    sg_c_on
  70.         NBYTE    sg_success
  71.         NALIGNLONG
  72.         NLABEL    sg_SIZEOF
  73.  
  74. ;--------------------------------
  75. ; print save game directory
  76. ; IN:    -
  77. ; OUT:    -
  78.  
  79. XBASE    = 50
  80. YBASE    = 40
  81. YSKIP    = 15
  82.  
  83. _sg_printdir    moveq    #XBASE,d0        ;x-pos
  84.         moveq    #YBASE-YSKIP,d1        ;first line
  85.         moveq    #'1',d2
  86.         moveq    #0,d3            ;amount saves
  87. .next        add.w    #YSKIP,d1        ;line skip
  88.         bsr    _pc
  89.         movem.l    d0/d2,-(a7)
  90.         add.w    #15,d0
  91.         sub.w    #'1',d2
  92.         mulu.w    #MAXNAMELEN,d2
  93.         lea    (sg_save_names,a5),a0
  94.         add.w    d2,a0
  95.         bsr    _ps
  96.         movem.l    (a7)+,d0/d2
  97.         addq.b    #1,d2
  98.         cmp.b    #'9',d2
  99.         bls    .next
  100.         rts
  101.  
  102. ;--------------------------------
  103. ; save a savegame
  104. ; IN:    D0 = size of the savegame
  105. ;    A0 = address to load savegame on
  106. ;    A1 = address of free memory for screen ($2800 bytes)
  107. ; OUT:    D0 = BOOL success
  108.  
  109. _sg_save    moveq    #0,d1
  110.         bra    _sg_degrade
  111. _sg_save_in    bsr    _sg_loaddir
  112.  
  113. .start        moveq    #7,d1
  114.         lea    _save,a0
  115.         bsr    _psc
  116.         add.w    #8,d1
  117.         lea    _saveselect,a0
  118.         bsr    _psc
  119.         add.w    #8,d1
  120.         lea    _esc,a0
  121.         bsr    _psc
  122.  
  123.         bsr    _sg_printdir
  124.  
  125. .keyloop    bsr    _sg_get_key
  126.         cmp.b    #$45,d0
  127.         beq    _sg_restore
  128.         
  129.         lea    (_keytrans),a0
  130.         move.b    (a0,d0.w),d1
  131.         cmp.b    #'1',d1
  132.         blo    .keyloop
  133.         cmp.b    #'9',d1
  134.         bhi    .keyloop
  135.         
  136.         moveq    #XBASE+9,d0
  137.         sub.w    #'1',d1
  138.         move.w    d1,d6            ;D6 = save no.
  139.         mulu    #YSKIP,d1
  140.         add.w    #YBASE-5,d1
  141.         move.w    d0,d2
  142.         add.w    #210,d2
  143.         move.w    d1,d3
  144.         add.w    #YSKIP-1,d3
  145.         bsr    _sg_rect
  146.         
  147.         move.w    d6,d0
  148.         mulu.w    #MAXNAMELEN,d0
  149.         lea    (sg_save_names,a5),a3
  150.         add.w    d0,a3            ;A3 = save name
  151.         
  152.         move.l    a3,a0
  153.         lea    (sg_tmpname,a5),a1
  154. .cpy        move.b    (a0)+,(a1)+
  155.         bne    .cpy
  156.  
  157. .chkname    moveq    #-1,d5
  158.         move.l    a3,a0
  159. .cnt        addq.w    #1,d5            ;D5 = charpos in save name
  160.         tst.b    (a0)+
  161.         bne    .cnt
  162.         
  163.         move.w    d5,d0
  164.         mulu    #CHARWIDTH,d0
  165.         add.w    #XBASE+15,d0
  166.         move.w    d0,(sg_c_x,a5)
  167.         move.w    d6,d1
  168.         mulu    #YSKIP,d1
  169.         add.w    #YBASE,d1
  170.         move.w    d1,(sg_c_y,a5)
  171.         st    (sg_c_on,a5)
  172.  
  173.         moveq    #15,d1
  174.         lea    _saveinsert,a0
  175.         bsr    _psc
  176.         
  177. .nextkey    bsr    _sg_get_key
  178.         cmp.b    #$43,d0            ;enter
  179.         beq    .return
  180.         cmp.b    #$44,d0            ;return
  181.         beq    .return
  182.         cmp.b    #$41,d0            ;backspace
  183.         beq    .bs
  184.         cmp.b    #$46,d0            ;delete
  185.         beq    .bs
  186.         cmp.b    #$45,d0            ;escape
  187.         beq    .esc
  188.         cmp.w    #MAXNAMELEN-1,d5
  189.         beq    .nextkey
  190.         lea    (_keytrans),a0
  191.         move.b    (a0,d0.w),d2
  192.         beq    .nextkey
  193.         move.b    d2,(a3,d5.w)
  194.         addq.w    #1,d5
  195.         move.w    (sg_c_x,a5),d0
  196.         move.w    (sg_c_y,a5),d1
  197.         add.w    #CHARWIDTH,(sg_c_x,a5)
  198.         bsr    _pc
  199.         bra    .nextkey
  200.  
  201. .bs        tst.w    d5
  202.         beq    .nextkey
  203.         bsr    _sg_cursoroff
  204.         subq.w    #1,d5
  205.         clr.b    (a3,d5.w)
  206.         bra    .chkname
  207.  
  208. .esc        bsr    _sg_cursoroff
  209.         lea    (sg_tmpname,a5),a0
  210.         move.l    a3,a1
  211. .cpy2        move.b    (a0)+,(a1)+
  212.         bne    .cpy2
  213.         bsr    _sg_initscr
  214.         bra    .start
  215.         
  216. .return        tst.w    d5            ;a name specified ?
  217.         beq    .esc
  218.         bsr    _sg_cursoroff
  219.  
  220.         moveq    #15,d1
  221.         lea    _saveconfirm,a0
  222.         bsr    _psc
  223.         
  224. .nextkey2    bsr    _sg_get_key
  225.         cmp.b    #$45,d0            ;escape
  226.         beq    .esc
  227.         cmp.b    #$43,d0            ;enter
  228.         beq    .confirmed
  229.         cmp.b    #$44,d0            ;return
  230.         bne    .nextkey2
  231.  
  232. .confirmed    lea    (sg_save_flags,a5),a0
  233.         st    (a0,d6.w)
  234.  
  235.         move.l    #SAVEDIRLEN,d0        ;size
  236.         moveq    #0,d1            ;offset
  237.         lea    (_sg_name),a0        ;filename
  238.         lea    (sg_save_id,a5),a1    ;address
  239.         move.w    #resload_SaveFileOffset,a2
  240.         bsr    _sg_exec_resload
  241.  
  242.         move.l    (sg_size,a5),d0        ;size
  243.         move.l    #SAVEDIRLEN,d1
  244.         bra    .loopin
  245. .loop        add.l    d0,d1            ;offset
  246. .loopin        subq.w    #1,d6
  247.         bpl    .loop
  248.         lea    (_sg_name),a0        ;filename
  249.         move.l    (sg_address,a5),a1    ;address
  250.         move.w    #resload_SaveFileOffset,a2
  251.         bsr    _sg_exec_resload
  252.  
  253.         st    (sg_success,a5)
  254.         bra    _sg_restore
  255.  
  256. ;--------------------------------
  257. ; disable text cursor
  258. ; IN:    -
  259. ; OUT:    -
  260.  
  261. _sg_cursoroff    sf    (sg_c_on,a5)
  262.         move.w    (sg_c_x,a5),d0
  263.         move.w    (sg_c_y,a5),d1
  264.         move.w    #' ',d2
  265.         bra    _pc
  266.  
  267. ;--------------------------------
  268. ; clear screen
  269. ; IN:    -
  270. ; OUT:    -
  271.  
  272. _sg_clrscr    movem.l    d0/a0,-(a7)
  273.  
  274.         move.l    (sg_screen,a5),a0
  275.         move.w    #(320*256/8)/4-1,d0
  276. .clr        clr.l    (a0)+
  277.         dbf    d0,.clr
  278.  
  279.         movem.l    (a7)+,d0/a0
  280.         rts
  281.  
  282. ;--------------------------------
  283. ; init screen
  284. ; IN:    -
  285. ; OUT:    -
  286.  
  287. _sg_initscr    movem.l    d0-d3/a0,-(a7)
  288.  
  289.         bsr    _sg_clrscr
  290.  
  291.     ;draw border
  292.     ;    moveq    #0,d0
  293.     ;    moveq    #0,d1
  294.     ;    move.w    #319,d2
  295.     ;    move.w    #199,d3
  296.     ;    bsr    _sg_rect
  297.     ;print info
  298.         move.w    #180,d1
  299.         lea    _info1,a0
  300.         bsr    _psc
  301.         add.w    #8,d1
  302.         lea    _info2,a0
  303.         bsr    _psc
  304.  
  305.         movem.l    (a7)+,d0-d3/a0
  306.         rts
  307.  
  308. ;--------------------------------
  309. ; load a savegame
  310. ; IN:    A0 = address to load savegame on
  311. ;    A1 = address of free memory for screen ($2800 bytes)
  312. ; OUT:    D0 = BOOL success
  313.  
  314. _sg_load    moveq    #-1,d1
  315.         bra    _sg_degrade
  316. _sg_load_in    bsr    _sg_loaddir
  317.         beq    .nosavegame
  318.  
  319. .start        moveq    #7,d1
  320.         lea    _load,a0
  321.         bsr    _psc
  322.         add.w    #8,d1
  323.         lea    _loadselect,a0
  324.         bsr    _psc
  325.         add.w    #8,d1
  326.         lea    _esc,a0
  327.         bsr    _psc
  328.         
  329.         bsr    _sg_printdir
  330.         
  331.         lea    (sg_save_names,a5),a0
  332.         moveq    #0,d0
  333.         
  334.  
  335. .keyloop    bsr    _sg_get_key
  336.         cmp.b    #$45,d0
  337.         beq    _sg_restore
  338.         
  339.         lea    (_keytrans),a0
  340.         moveq    #0,d1
  341.         move.b    (a0,d0.w),d1
  342.         cmp.b    #'1',d1
  343.         blo    .keyloop
  344.         cmp.b    #'9',d1
  345.         bhi    .keyloop
  346.         
  347.         lea    (sg_save_flags,a5),a0
  348.         tst.b    (-'1',a0,d1.w)
  349.         beq    .keyloop
  350.         
  351.         moveq    #XBASE+9,d0
  352.         sub.w    #'1',d1
  353.         move.w    d1,d6            ;D6 = save no.
  354.         mulu    #YSKIP,d1
  355.         add.w    #YBASE-5,d1
  356.         move.w    d0,d2
  357.         add.w    #210,d2
  358.         move.w    d1,d3
  359.         add.w    #YSKIP-1,d3
  360.         bsr    _sg_rect
  361.         
  362.         moveq    #15,d1
  363.         lea    _loadconfirm,a0
  364.         bsr    _psc
  365.         
  366. .nextkey2    bsr    _sg_get_key
  367.         cmp.b    #$43,d0            ;enter
  368.         beq    .confirmed
  369.         cmp.b    #$44,d0            ;return
  370.         beq    .confirmed
  371.         cmp.b    #$45,d0            ;escape
  372.         bne    .nextkey2
  373.         bsr    _sg_initscr
  374.         bra    .start
  375.  
  376. .confirmed    move.l    (sg_size,a5),d0        ;size
  377.         move.l    #SAVEDIRLEN,d1
  378.         bra    .loopin
  379. .loop        add.l    d0,d1            ;offset
  380. .loopin        subq.w    #1,d6
  381.         bpl    .loop
  382.         lea    (_sg_name),a0        ;filename
  383.         move.l    (sg_address,a5),a1    ;address
  384.         move.w    #resload_LoadFileOffset,a2
  385.         bsr    _sg_exec_resload
  386.  
  387.         st    (sg_success,a5)
  388.         bra    _sg_restore
  389.  
  390. .nosavegame    moveq    #60,d1
  391.         lea    _loadno1,a0
  392.         bsr    _psc
  393.         add.w    #8,d1
  394.         lea    _loadno2,a0
  395.         bsr    _psc
  396.         bsr    _sg_get_key
  397.         bra    _sg_restore
  398.  
  399. ;--------------------------------
  400. ; loads save directory
  401. ; IN:    -
  402. ; OUT:    D0 = BOOL success
  403. ;    flags on D0
  404.  
  405. _sg_loaddir    lea    (_sg_name),a0
  406.         move.w    #resload_GetFileSize,a2
  407.         bsr    _sg_exec_resload
  408.         tst.l    d0
  409.         beq    .nocurrentfile
  410.  
  411.         move.l    #SAVEDIRLEN,d0        ;size
  412.         moveq    #0,d1            ;offset
  413.         lea    (_sg_name),a0        ;filename
  414.         lea    (sg_save_id,a5),a1    ;address
  415.         move.w    #resload_LoadFileOffset,a2
  416.         bsr    _sg_exec_resload
  417.         cmp.l    #"Wepl",(sg_save_id,a5)
  418.         bne    .nocurrentfile
  419.         moveq    #